package com.cl.pile.rule.func;

import com.alibaba.fastjson.JSONObject;
import com.cl.pile.rule.process.RuleMatcher;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author chenyitao
 * @date 2021/6/8
 */
public class MaxFunc extends NumBaseFunc {

    @Override
    public Object func(List<Object> data, String rootVar, Object root, JSONObject ruleJson, RuleMatcher ruleMatcher) {
        BigDecimal min = numFuncCb(new BigDecimal(0), data, ruleJson, ruleMatcher, rootVar, root,
                (oldNum, dataValue) -> {
                    if (oldNum.compareTo(dataValue) < 0) {
                        return dataValue;
                    }
                    return null;
                });
        return min.toString();
    }

    @Override
    public String funcName() {
        return "取最大值";
    }
}
